﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;


namespace CNotebook
{
    public class ExchangeCurrencyManager:ConnectionManager
    {
        public void AddCurrency(string sCurrCode, string sCurrName)
        {
            SqlCommand oCommand = new SqlCommand();

            oCommand.Connection = this.Connection;
            oCommand.CommandText = "INSERT INTO CURRNCY (CURRCODE, CURRNAME) VALUES (@CURRCODE, @CURRNAME) ";

            oCommand.Parameters.Add(new SqlParameter("@CURRCODE", sCurrCode));
            oCommand.Parameters.Add(new SqlParameter("@CURRNAME", sCurrName));

            oCommand.ExecuteNonQuery();
        }

        public void AddCurrency(CurrencyUnit oUnit)
        {
            SqlCommand oCommand = new SqlCommand();

            oCommand.Connection = this.Connection;
            oCommand.CommandText = "INSERT INTO CURRNCY (CURRCODE, CURRNAME) VALUES (@CURRCODE, @CURRNAME) ";

            oCommand.Parameters.Add(new SqlParameter("@CURRCODE", oUnit.CurrencyCode));
            oCommand.Parameters.Add(new SqlParameter("@CURRNAME", oUnit.CurrencyName));
            oCommand.ExecuteNonQuery();
        }

        public DataTable GetCurrency()
        {
            SqlCommand oCommmand = new SqlCommand();
            SqlDataAdapter oAdapter = new SqlDataAdapter();
            DataSet ds = new DataSet();

            oCommmand.Connection = this.Connection;
            oCommmand.CommandText = "SELECT * FROM CURRNCY";

            oAdapter.SelectCommand = oCommmand;
            oAdapter.Fill(ds);
            return ds.Tables[0];
        }
    }
}
